home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 November: Tool Chest / Dev.CD Nov 94.toast / Sample Code / Snippets / Development Tools & Languages / DTSCPlusLibrary / Sources / GraphicsEnvTest.cp < prev    next >
Encoding:
Text File  |  1993-01-14  |  3.6 KB  |  146 lines  |  [TEXT/MPS ]

  1. /* _________________________________________________________________________________________________________ //
  2.   Copyright © 1993 Apple Computer, Inc. All rights reserved.
  3.   Macintosh Developer Technical Support.C++ Macintosh Toolbox Framework.
  4.   Date: 1/2/93
  5.   Revision comments are at the end of this file.
  6.   ---
  7.   GraphicsEnvTest.cp contains the needed test functions for testing out graphics environment utility classes.
  8.   _________________________________________________________________________________________________________ */
  9.  
  10. // HEADER FILES
  11. // Main interface for the application framework
  12. #ifndef _APPLICATION_
  13. #include "Application.h"
  14. #endif
  15.  
  16. // For graphics environment testing
  17. #ifndef _GRAPHICSENV_
  18. #include "GraphicsEnv.h"
  19. #endif
  20.  
  21. // CONSTANTS
  22. const short H = 10;                                // horizontal offset of graphics drawing in window
  23. const short V = 20;                                // initial vertical offset of graphics in window
  24. const short DELTA = 15;                            // delta value of vertical offsets 
  25.  
  26.  
  27. // CLASSES
  28. class TMyApplication : public TGUIApplication
  29. // Our sub-TApplication class, override DoCreateDocument for creation of a special window.
  30. {
  31. public:
  32.     TMyApplication();
  33.     virtual void DoCreateDocument();
  34. };
  35.  
  36.  
  37. class TMyWindow : public TWindow
  38. // Override Draw to specify what is drawn in the window.
  39. {
  40. public:
  41.     virtual void Draw();
  42. };
  43.  
  44.  
  45. TMyApplication::TMyApplication()
  46. {
  47. }
  48.  
  49.  
  50. // MEMBER FUNCTIONS
  51. #pragma segment Application
  52. void TMyApplication::DoCreateDocument()
  53. {
  54.     Str255 myTitle;
  55.     Pstrcpy(myTitle, "\pGraphics Env. Tests");
  56.  
  57.     // Create this time my TMyWindow document, and add it to the TApplication list.
  58.     TMyWindow * aWindow = new TMyWindow;
  59.     aWindow->SetTitle(&myTitle);
  60.     this->AddDocument(aWindow);
  61.  
  62.     // Quick test, show and hide the window.
  63.     aWindow->Hide();
  64.     Delay(60 * 1, NULL);
  65.     aWindow->Show();
  66. }
  67.  
  68.  
  69. // Global styles
  70. TFontEnvironment myGenevaBold(srcOr,
  71.                               geneva,
  72.                               9,
  73.                               bold);
  74. TFontEnvironment myGenevaInvBold(notSrcCopy,
  75.                                  geneva,
  76.                                  10,
  77.                                  bold);
  78.  
  79. TPenEnvironment myThickLine(srcOr,
  80.                             qd. dkGray,
  81.                             5,
  82.                             5);
  83.  
  84. TColorEnvironment myMetalGray(36000,
  85.                               40500,
  86.                               37500);
  87. TColorEnvironment myMetalBlue(26312,
  88.                               14340,
  89.                               47359);
  90.  
  91.  
  92. #pragma segment Window
  93. void TMyWindow::Draw()
  94. {
  95.     // Paint background in metal color
  96.     myMetalGray.SetForeground();                // set gray foreground
  97.     Rect windowRect = this->GetExtent();        // get window extent
  98.     ::PaintRect(&windowRect);                    // paint background with gray
  99.  
  100.     // Set real background & foreground colors
  101.     myMetalBlue.SetForeground();                // set blue paint foreground
  102.     myMetalGray.SetBackground();                // set gray background
  103.  
  104.     // Draw something into my special window.
  105.     ::MoveTo(H, V);
  106.     myGenevaBold.Set();
  107.     ::DrawString("\pThis is a color and Quickdraw test.");
  108.  
  109.     ::MoveTo(H, V + DELTA);
  110.     myGenevaInvBold.Set();
  111.     ::DrawString("\pI will use various classes, do");
  112.  
  113.     ::MoveTo(H, V + 2 * DELTA);
  114.     myGenevaBold.Reset();                        // reset font values to default state
  115.     ::DrawString("\pthey they work or not?");
  116.  
  117.     ::MoveTo(H, V + 3 * DELTA);
  118.     myThickLine.Set();                            // draw thick line
  119.     ::Line(200, 0);
  120.     myThickLine.Reset();                        // back to thin lines
  121.     ::MoveTo(H, V + 4 * DELTA);
  122.     ::Line(200, 0);
  123.     ::MoveTo(H, V + 5 * DELTA);
  124.     ::Line(200, 0);
  125.  
  126.     ::PenNormal();                                // restore pen
  127. }
  128.  
  129.  
  130. // M A I N   F U N C T I O N
  131. void main(void)
  132. {
  133.     TMyApplication * myApp = new TMyApplication;
  134.     myApp->Start();
  135. }
  136.  
  137.  
  138. // _________________________________________________________________________________________________________ //
  139.  
  140. /*    Change History (most recent last):
  141.   No        Init.    Date        Comment
  142.   1            khs        1/2/93        New file
  143.   2            khs        1/7/93        Cleanup
  144. */
  145.  
  146.